require("../../19EB63A409CE66DF7F8D0BA3775A8AF7.js");

var t = getApp();

Page({
    data: {
        pageIsLoad: !1,
        is_check: -1,
        is_ios_pay: 0,
        system: "",
        vip_expire_time: "",
        vipList: [],
        vip_id: 0,
        paying: !1
    },
    onLoad: function(a) {
        var i = this;
        this.setData({
            system: t.globalData.system
        }), t.util.checkLogin().then(function() {
            i.getWxappInfo(), i.getVipList(), i.setData({
                pageIsLoad: !0
            });
        });
    },
    onShow: function() {
        this.data.pageIsLoad && this.getBalance();
    },
    getVipList: function() {
        var a = this;
        t.util.request({
            url: "/wxapp/getVipList"
        }).then(function(t) {
            var i = t.data;
            i.forEach(function(t) {
                t.is_default && a.setData({
                    vip_id: t.id
                });
            }), a.setData({
                vipList: i
            });
        });
    },
    getBalance: function() {
        var a = this;
        t.util.request({
            url: "/wxapp/getBalance",
            loading: !1
        }).then(function(t) {
            a.setData({
                balance: t.data.balance,
                vip_expire_time: t.data.vip_expire_time
            });
        });
    },
    chooseVip: function(t) {
        var a = t.currentTarget.dataset.id;
        this.setData({
            vip_id: a
        });
    },
    getWxappInfo: function() {
        var a = this;
        t.util.request({
            url: "/wxapp/getWxappInfo",
            loading: !1
        }).then(function(t) {
            a.setData({
                is_check: t.data.is_check,
                is_ios_pay: t.data.is_ios_pay
            });
        });
    },
    doPayVip: function() {
        var a = this;
        if (this.data.paying) return !1;
        var i = this.data.vip_id;
        if (0 == i) return t.util.message("请选择VIP套餐"), !1;
        this.setData({
            paying: !0
        }), setTimeout(function() {
            a.setData({
                paying: !1
            }, 2e3);
        }), t.util.request({
            url: "/wxapp/createOrder",
            data: {
                vip_id: i
            }
        }).then(function(a) {
            wx.requestPayment({
                timeStamp: a.data.timeStamp,
                nonceStr: a.data.nonceStr,
                package: a.data.package,
                signType: "MD5",
                paySign: a.data.paySign,
                success: function(a) {
                    t.util.message("支付成功", "error", function() {
                        wx.redirectTo({
                            url: "/pages/index/index"
                        });
                    });
                },
                fail: function(a) {
                    t.util.message("支付失败，请重试", "error");
                }
            });
        });
    }
});